# coding: utf8
import os
plugin_uc_flatpage_cwd = os.getcwd()
plugin_uc_flatpage_format=MARKMIN

## This file was created using static/plugin_plugin/controller_template

# this need work for a multiple plugin senerio
auth.settings.on_failed_authorization = URL(r=request,f='failed_authorization',args=T('you need additional permissions to perform this action'))

def index():
    return dict(message="hello from plugin_uc_flatpage.py function index")

@auth.requires_login()
def site_user():
    return dict(message="hello from plugin_plugin.py function site_user")

@auth.requires_membership('plugin_uc_flatpage_config')    
def configure():
    return dict(message="hello from plugin_plugin.py function admin")

@auth.requires_membership('plugin_uc_flatpage_admin')
def admin():
    return dict(message="hello from plugin_plugin.py function admin")


def display_static():
    """
    Displays app_name/plugin_uc_flatpage/static/
    """
    file_name=request.args(0) or redirect(URL('index'))    
    file_path = os.path.join(plugin_uc_flatpage_cwd,'applications',request.application, 'static', 'plugin_uc_flatpage', file_name)
    if os.path.exists(file_path):
        content=open(file_path,'r').read()
        body = MARKMIN(content)
    else:
        body = MARKMIN('file not found')
    return dict(body=body)

def failed_authorization():
    if len(request.args):
        message=str(request.args[0])
    else:
        message=T("not authorized")
    return dict(message=message)
